using System;
using System.Collections;
using System.Collections.Generic;
using FrameWork;
using UnityEngine;
using Random = UnityEngine.Random;

public class NPCSpawnManager : MonoBehaviour
{
    [Header("牛生成设置")]
    [SerializeField] private GameObject slime;
    [SerializeField] private float slimeNum = 10;
    [SerializeField] private Vector3 leftSlimePos;
    [SerializeField] private Vector3 rightSlimePos;
    
    [Header("牛生成设置")]
    [SerializeField] private GameObject cow;
    [SerializeField] private float cowNum = 10;
    [SerializeField] private Vector3 leftCowPos;
    [SerializeField] private Vector3 rightCowPos;
    
    
    // 
    private void Start()
    {
        for (int i = 0; i < slimeNum; i++)
        {
            SpawnSlime();
        }
        
        for (int i = 0; i < cowNum; i++)
        {
            SpawnCow();
        }
        
        EventSystem.Instance.AddListener(EventName.EVENT_SLIME_SPAWN, SpawnSlime);
        EventSystem.Instance.AddListener(EventName.EVENT_SLIME_COW, SpawnCow);
    }

    private void SpawnSlime()
    {
        GameObject obj = ObjectPool.Instance.Spawn("Slime");
        obj.transform.SetParent(transform);
        obj.GetComponent<INPCSpawn>().Spawn(leftSlimePos, rightSlimePos);
            
        // 设置随机位置
        obj.transform.position = new Vector3(Random.Range(leftSlimePos.x, rightSlimePos.x), Random.Range(leftSlimePos.y, rightSlimePos.y), 0);
    }
    
    private void SpawnCow()
    {
        GameObject obj = ObjectPool.Instance.Spawn("Cow");
        obj.transform.SetParent(transform);
        obj.GetComponent<INPCSpawn>().Spawn(leftCowPos, rightCowPos);
            
        // 设置随机位置
        obj.transform.position = new Vector3(Random.Range(leftCowPos.x, rightCowPos.x), Random.Range(leftCowPos.y, rightCowPos.y), 0);
    }
}